package com.huluobo.a2202mvvm_im_douyindemo.mvpDemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.huluobo.a2202mvvm_im_douyindemo.R;

public class MVPLoginDemoActivity extends AppCompatActivity implements LoginView {
    private LoginPresenter presenter = new LoginPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvplogin_demo);
        EditText username = findViewById(R.id.username);
        EditText password = findViewById(R.id.password);

        Button login = findViewById(R.id.login);

        login.setOnClickListener(v -> presenter.login(username.getText().toString(), password.getText().toString()));
    }

    @Override
    public void onSuccess(UserBean bean) {
        Toast.makeText(this, "登录成功:" + bean.getUsername(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailed(String error) {
        Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
    }
}